﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ConsumeQuery.aspx.cs" Inherits="WISD.CarFriend.Web.Admin.OA.ConsumeManage.ConsumeQuery" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>会员卡消费管理</title>
    <link href="../../Content/CSS/ClientCSS/qlsale.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/CSS/ClientCSS/Table.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/CSS/ClientCSS/blue.css" rel="stylesheet" type="text/css" />
    <script src="/Admin/Scripts/ClientScripts/Page.js" type="text/javascript"></script>
    <script src="/Admin/Scripts/ClientScripts/CodyyForm.js" type="text/javascript"></script>
    <script src="/Admin/Scripts/ClientScripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="/Admin/Scripts/DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="/Admin/Scripts/ClientScripts/SplitPage.js" type="text/javascript"></script>
    <script src="/Admin/Scripts/ClientScripts/jquery.artDialog.min.js" type="text/javascript"></script>
    <script src="../../Scripts/WisdScript/Common.js" type="text/javascript"></script>
</head>
<body>
    <div style="height: auto;">
        <table class="adduser" align="center" border="0" cellpadding="0" cellspacing="0"
            width="100%" bgcolor="#F2F7F5">
            <tbody>
                <tr>
                    <td colspan="6" class="bigTitle" height="40">
                        <strong>会员卡消费查询</strong>
                    </td>
                </tr>
                <tr>
                </tr>
                <tr>
                    <td class="sctitle" style="width: 81px;">
                        会员卡号：
                    </td>
                    <td style="width: 162px;">
                        <input id="txtVipCId" class="xstxt" type="text" />
                    </td>
                    <td class="sctitle" style="width: 50px;">
                    </td>
                    <td class="sctitle" style="width: 81px;">
                        会员姓名：
                    </td>
                    <td>
                        <input id="txtVipSearchName" class="xstxt" type="text" />
                    </td>
                </tr>
                <tr>
                    <td class="sctitle" style="width: 81px;">
                        会员编号：
                    </td>
                    <td style="width: 162px;">
                        <input id="txtVipId" class="xstxt" type="text" />
                    </td>
                    <td class="sctitle" style="width: 50px;">
                    </td>
                    <td class="sctitle" style="width: 81px;">
                        消费项目：
                    </td>
                    <td>
                        <input id="txtConsumeIDItem" name="txtConsumeIDItem" class="xstxt" type="text" />
                    </td>
                </tr>
                <tr>
                    <td class="sctitle" style="width: 81px;">
                        消费时间：
                    </td>
                    <td colspan="6">
                        <input id="txtConsumeTime" name="txtConsumeTime" onclick="WdatePicker()" class="xstxt"
                            type="text" />
                        -
                        <input id="txtConsumeEndTime" name="txtConsumeEndTime" onclick="WdatePicker()" class="xstxt"
                            type="text" />
                    </td>
                </tr>
                <tr>
                    <td class="sctitle" style="width: 81px;">
                        消费地点：
                    </td>
                    <td colspan="6">
                        <select id="txtConsumeLocation" style="width: 315px;">
                        </select>
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="fenline">
                        &nbsp;
                        <input value="搜索" class="twobtn" type="button" id="btnSearch" />&nbsp;&nbsp;
                    </td>
                </tr>
                <tr>
                    <td colspan="6">
                        <table rules="all" class="tableStyle">
                            <thead>
                                <tr>
                                    <th scope="col" style="display: none;">
                                        序号
                                    </th>
                                    <th scope="col">
                                        会员卡号
                                    </th>
                                    <th scope="col">
                                        会员编号
                                    </th>
                                    <th scope="col">
                                        会员车号
                                    </th>
                                    <th scope="col">
                                        消费时间
                                    </th>
                                    <th scope="col">
                                        消费地点
                                    </th>
                                    <th scope="col">
                                        消费项目
                                    </th>
                                    <th scope="col">
                                        备注
                                    </th>
                                    <th scope="col">
                                        是否已回访
                                    </th>
                                    <th scope="col">
                                        操作
                                    </th>
                                </tr>
                            </thead>
                            <tbody id="databody">
                            </tbody>
                            <tfoot id="footer" class="div_footer">
                            </tfoot>
                        </table>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div id="registerdiv" class="registerdiv" style="width: 620px;">
        <table class="addTable" align="center" border="0" cellpadding="0" cellspacing="0"
            width="100%" style="margin-right: 20px;">
            <tbody>
                <tr class="topTitle">
                    <td colspan="4" style="margin-top: -3px;">
                        <ul>
                            <li class="leftli">会员卡消费查询</li>
                            <li class="rightli" onclick="$('#registerdiv').hide();">
                                <img alt="关闭" title="关闭" id="close" src="/Admin/Content/Images/tdClose_Hover.png" /></li>
                        </ul>
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        会员卡号：
                    </td>
                    <td>
                        <input id="MemberCardID" name="MemberCardID" class="stxt" type="text" reg="\S" needcheck="yes"
                            tip="['会员卡号不能为空','只能为中英文','长度在1-50之间']" scope="1,50" clear="yes">
                        <span></span>
                    </td>
                    <td class="sctitle_four">
                        会员卡状态：
                    </td>
                    <td>
                        <input id="State" name="State" class="stxt txtgray" type="text" readonly="readonly">
                        <span></span>
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        会员编号：
                    </td>
                    <td>
                        <input id="MemberID" name="MemberID" class="stxt txtgray" type="text" class="txtgray"
                            readonly="readonly">
                        <span></span>
                    </td>
                    <td class="sctitle_four">
                        会员姓名：
                    </td>
                    <td>
                        <input id="txtVipName" name="txtVipName" class="stxt txtgray" type="text" class="txtgray"
                            readonly="readonly">
                        <span></span>
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        剩余金额：
                    </td>
                    <td>
                        <input id="ResidualAmount" name="ResidualAmount" class="stxt txtgray" type="text"
                            class="txtgray" readonly="readonly">
                        <span></span>
                    </td>
                    <td class="sctitle_four">
                        消费时间：
                    </td>
                    <td>
                        <input id="ConsumeTime" name="ConsumeTime" class="stxt" type="text" reg="^\d{4}(\-|\/|.)\d{1,2}\1\d{1,2}$"
                            needcheck="yes" tip="['消费时间不能为空','格式不对']" clear="yes">
                        <span></span>
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        消费项目：
                    </td>
                    <td>
                        <select id="ConsumeIDItem" style="width: 120px">
                        </select>
                    </td>
                    <td class="sctitle_four">
                        消费金额：
                    </td>
                    <td>
                        <input id="ConsumeAmount" name="ConsumeAmount" class="stxt" type="text" reg="^[1-9]\d*$"
                            needcheck="yes" tip="['消费金额不能为空','只能为正整数','长度在1-50之间']" scope="1,50" clear="yes">
                        <span></span>
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        实收金额:
                    </td>
                    <td>
                        <input id="PaidAmount" name="PaidAmount" class="stxt" type="text" reg="^[1-9]\d*$"
                            needcheck="yes" tip="['实收金额不能为空','只能为正整数','长度在1-50之间']" scope="1,50" clear="yes">
                        <span></span>
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        消费地点：
                    </td>
                    <td colspan="3">
                        <select id="ConsumeLocation" style="width: 300px">
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        备注：
                    </td>
                    <td colspan="3">
                        <textarea id="Memo1" cols="30" rows="5" style="overflow: hidden; display: block;
                            resize: none;"></textarea>
                    </td>
                </tr>
                <tr>
                    <td colspan="4" style="height: 15px;">
                    </td>
                </tr>
                <tr>
                    <td id="btnGroup" colspan="4" align="center" style="text-align: center;">
                        <input value="修改" id="btnEdit" class="twobtn" type="button" />&nbsp;&nbsp;
                        <input value="确定" id="btnSave" class="twobtn" type="button" />&nbsp;&nbsp;
                        <input id="btnRest" class="twobtn" value="重置" type="button" />
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div id="ReturnVisitdiv" class="registerdiv" style="width: 660px;">
        <table class="addTable" align="center" border="0" cellpadding="0" cellspacing="0"
            width="100%" style="margin-right: 20px;">
            <tbody>
                <tr class="topTitle">
                    <td colspan="4" style="margin-top: -3px;">
                        <ul>
                            <li class="leftli">会员回访管理</li>
                            <li class="rightli" onclick="$('#ReturnVisitdiv').hide();">
                                <img alt="关闭" title="关闭" id="close1" src="/Admin/Content/Images/tdClose_Hover.png" /></li>
                        </ul>
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        会员编号：
                    </td>
                    <td>
                        <input id="txtMemberID" name="txtMemberID" class="stxt txtgray" type="text" readonly="readonly" />
                    </td>
                    <td class="sctitle_four">
                        会员姓名：
                    </td>
                    <td>
                        <input id="txtMemberName" name="txtMemberName" class="stxt txtgray" type="text" readonly="readonly" />
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        消费时间：
                    </td>
                    <td>
                        <input id="txtConsumeDate" name="txtConsumeDate" class="stxt txtgray" type="text"
                            readonly="readonly" />
                    </td>
                    <td>
                        特约商户负责人：
                    </td>
                    <td>
                        <input id="txtShopLeader" name="txtShopLeader" class="stxt txtgray" type="text" readonly="readonly" />
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        车号：
                    </td>
                    <td>
                        <input id="txtCarNum" name="txtCarNum" class="stxt txtgray" type="text" readonly="readonly" />
                    </td>
                    <td class="sctitle_four">
                        消费项目：
                    </td>
                    <td>
                        <input id="ConsumeItem" name="ConsumeItem" class="stxt txtgray" type="text" readonly="readonly" />
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        回访方式：
                    </td>
                    <td>
                        <select id="ReturnVisitType" style="width: 120px;">
                            <option value="1">电话</option>
                        </select>
                    </td>
                    <td class="sctitle_four">
                        状态：
                    </td>
                    <td>
                        <select id="selState" style="width: 120px;">
                            <option value="1">登记状态</option>
                            <option value="2">执行状态</option>
                            <option value="3">完成状态</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        开始时间：
                    </td>
                    <td>
                        <input id="txtStartTime" name="StartTime" class="stxt txtgray" type="text" readonly="readonly" />
                    </td>
                    <td class="sctitle_four">
                        结束时间：
                    </td>
                    <td>
                        <input id="txtEndTime" name="EndTime" class="stxt txtgray" type="text" readonly="readonly" />
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        会员满意度：
                    </td>
                    <td>
                        <select id="selSatisfaction" style="width: 120px;">
                            <option value="0">满意</option>
                            <option value="1">不满意</option>
                        </select>
                    </td>
                    <td class="sctitle_four">
                        受派员工:
                    </td>
                    <td>
                        <select id="SelSendEmployee" style="width: 120px;">
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        会员投诉：
                    </td>
                    <td>
                        <textarea id="Complaint" cols="30" rows="5" style="overflow: hidden; display: block;
                            resize: none;" clear='yes'></textarea>
                    </td>
                    <td class="sctitle_four">
                        处理结果：
                    </td>
                    <td>
                        <textarea id="Result" cols="30" rows="5" style="overflow: hidden; display: block;
                            resize: none;" clear='yes'></textarea>
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        备注：
                    </td>
                    <td colspan="3">
                        <textarea id="Memo" clear='yes' cols="30" rows="5" style="overflow: hidden; display: block;
                            resize: none;"></textarea>
                    </td>
                </tr>
                <tr>
                    <td colspan="4" style="height: 15px;">
                    </td>
                </tr>
                <tr>
                    <td id="Td1" colspan="4" align="center" style="text-align: center;">
                        <input value="保存" id="btnSaveReturn" class="twobtn" type="button" />
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</body>
</html>
<script type="text/javascript">
    //赋值操作
    function EditEntity() {
        var rs = Page.Static.Rs[0];
        $("#MemberCardID").val(rs["MemberCardID"]);
        $("#State").val(rs["State"]);
        $("#MemberID").val(rs["MemberID"]);
        $("#txtVipName").val(rs["Name"]);
        $("#ResidualAmount").val(rs["ResidualAmount"]);
        $("#ConsumeTime").val(rs["consumeTime"].split(" ")[0]);
        $("#ConsumeLocation").html("<option>" + rs["ConsumeLocation"] + "</option>");
        $("#ConsumeIDItem").html("<option>" + rs["ConsumeIDItem"] + "</option>");
        $("#ConsumeAmount").val(rs["ConsumeAmount"]);
        $("#PaidAmount").val(rs["PaidAmount"]);
        $("#Memo1").val(rs["Memo"]);
    };

    //专门用来保存某个记录的详细消息
    var rs = {};
    var MainPK = "";
    var Condition = "";
    var CurrentPage = 1;

    //获取查询条件
    var GetCondition = function () {
        var MemberCardID = $("#txtVipCId").val() || "0"; //会员卡编号
        var MemberID = $("#txtVipId").val() || "0"; //会员编号
        var VipName = $("#txtVipSearchName").val() || "0";  //会员姓名
        var ConsumeTime = $("#txtConsumeTime").val() || "0";  //消费开始时间
        var ConsumeEndTime = $("#txtConsumeEndTime").val() || "0";  //消费结束时间
        var ConsumeLocation = $("#txtConsumeLocation  option:selected'").text() || "0";  //消费地点
        var ConsumeIDItem = $("#txtConsumeIDItem").val() || "0";  //消费项目
        ConsumeLocation = ConsumeLocation == "---请选择---" ? "0" : ConsumeLocation;
        return MemberCardID + "@" + MemberID + "@" + VipName + "@" + ConsumeTime + "@" + ConsumeLocation + "@" + ConsumeIDItem + "@" + ConsumeEndTime;
    };

    //加载数据
    var InitPage = function () {
        Page.GetData({ "Control": "/Admin/Control/Consume.ashx", "Action": "QueryInit", "first": true, "colspan": 10,
            "Condition": Condition, "databody": "databody", "footer": "footer", "ActionBtn": "<a href='javascript:;' action='ReturnVisitAdd'>[会员回访]</a>"
        });
    };

    $(document).ready(function () {
        $.post("/Admin/Control/Consume.ashx", { Action: "GetConsumeQuery" }, function (data) {
            if (data) {
                $("#btnSearch").attr('disabled', true);
                alert("当前登录用户无权限执行[搜索]功能！");
                return;
            }
            GetConsumeLocation();
            //第一次加载数据
            Condition = GetCondition();
            InitPage();
        });

        //获取消费地点
        var GetConsumeLocation = function () {
            $.post("/Admin/Control/Consume.ashx", { Action: "GetConsumeLocation", PageID: "ConsumeQuery" }, function (data) {
                if (!data) {
                    $("#txtConsumeLocation").html("<option value=''>无</option>");
                }
                else {
                    var jsonArr = eval("(" + data + ")");
                    var citystr = "";
                    if (jsonArr.length != 1) {
                        citystr = "<option value=0>---请选择---</option>";
                    }
                    for (var i = 0; i < jsonArr.length; i++) {
                        citystr += "<option value=" + jsonArr[i]["Id"] + ">" + jsonArr[i]["Address"] + "</option>";
                    }
                }
                $("#txtConsumeLocation").html(citystr).change();
            });
        };

        //获取员工表信息
        var LoadExmployee = function () {
            $.post("/Admin/Control/ReturnVisit.ashx", { "Action": "GetEp" }, function (data) {
                if (!data) {
                    $("#SelSendEmployee").html("<option value=''>无</option>");
                    return;
                }
                var jsonArr = eval("(" + data + ")");
                var citystr = "";
                for (var i = 0; i < jsonArr.length; i++) {
                    citystr += "<option value=" + jsonArr[i]["EmployeeID"] + ">" + jsonArr[i]["Name"] + "</option>";
                }
                $("#SelSendEmployee").html(citystr).change();
            });
        };

        //点击搜索按钮
        $("#btnSearch").click(function () {
            Condition = GetCondition();
            CurrentPage = 1;
            InitPage();
        });

        //获取消费信息
        var GetConsumeInfo = function (obj) {
            txtConsumeID = obj;
            $.post("/Admin/Control/Consume.ashx", { Action: "GetConsumeInfo", ConsumeID: obj }, function (data) {
                if (data) {
                    var jsonArr = eval("(" + data + ")");
                    var citystr = "";
                    for (var i = 0; i < jsonArr.length; i++) {
                        $("#txtMemberID").val(jsonArr[i]["MemberID"]);
                        $("#txtMemberName").val(jsonArr[i]["Name"]);
                        $("#txtConsumeDate").val(jsonArr[i]["ConsumeTime"]);
                        $("#txtShopLeader").val(jsonArr[i]["Leader"]);
                        $("#txtCarNum").val(jsonArr[i]["VehicleNo"]);
                        $("#ConsumeItem").val(jsonArr[i]["ConsumeItem"]);
                    }
                }
            });
        };

        //重置表单
        var ResetForm = function () {
            $(".addTable").find("input[type='text'][clear='yes'],textarea[clear='yes']").val("");
            $(".addTable").find("input,textarea,select").attr("disabled", false);
        };

        //在Table中点击修改、删除 
        $("#databody").click(function (e) {
            var that = this;
            var e = e || window.event;
            var target = e.srcElement || e.target;
            if ($(target).is("a")) {
                var action = $(target).attr("action");
                var main = $(target).parent().parent().attr("main");
                if (!action.localeCompare("ReturnVisitAdd")) {    //编辑
                    var state = $(target).parent().parent().children('[id=State]')[0].innerText;
                    if (state == "是") {
                        alert("此记录已回访，无法再回访！");
                        return;
                    }
                    ResetForm();
                    $("#ReturnVisitdiv .leftli").html("会员回访新增");
                    var divobj = $("#ReturnVisitdiv");
                    $("#txtStartTime").val(getNowFormatDate());
                    GetConsumeInfo(main);
                    LoadExmployee();
                    Page.divCenter(divobj[0]);
                }
                (! -[1, ]) ? e.cancelBubble = true : e.stopPropagation();
            }
        }).dblclick(function (e) {    //双击查看详细信息
            var that = this;
            var e = e || window.event;
            var target = e.srcElement || e.target;
            if ($(target.parentNode).is("tr")) {
                var main = $(target.parentNode).attr("main");
                $("#btnEdit,#btnSave,#btnRest").hide();
                $("#registerdiv .addTable").find("input,textarea,select").attr("disabled", true);
                $("#registerdiv .leftli").html("会员卡详细信息");
                var divobj = $("#registerdiv");
                Page.divCenter(divobj[0]).GetOne({ "Main": main });
                (! -[1, ]) ? e.cancelBubble = true : e.stopPropagation();
            }
        });
    });
    var txtConsumeID = "";
    //点击保存按钮
    $("#btnSaveReturn").click(function () {
        var Result = Form.Validator({ id: "ReturnVisitdiv" });
        if (Result) {
            var _$ = function (id) { return document.getElementById(id); };
            var data = {
                Action: 'AddEntity'
                      , ConsumeID: txtConsumeID
                      , ConsumeDate: $.trim($("#txtConsumeDate").val())
                      , ReturnVisitType: $.trim($("#ReturnVisitType").val())
                      , State: $.trim($("#selState").val())
                      , StartTime: $.trim($("#txtStartTime").val())
                      , EndTime: $.trim($("#txtEndTime").val())
                      , Satisfaction: $.trim($("#selSatisfaction").val())
                      , SendEmployee: $.trim($("#SelSendEmployee").val())
                      , Complaint: $.trim($("#Complaint").val())
                      , Result: $.trim($("#Result").val())
                      , Memo: $.trim($("#Memo").val())
                      , Reviser: ""
                      , ReviseDate: ""
            };
            $.post("/Admin/Control/ReturnVisit.ashx", data, function (data) {
                if (data.split(",")[0] === "Success") {
                    alert("添加成功!");
                    $("#ReturnVisitdiv").hide();
                    InitPage();
                }
                else {
                    alert("修改失败!");
                }
            });
        }
    });

    $("#selState").change(function () {
        var SelectID = $("#selState  option:selected'").val();
        if (SelectID == "3") {   //完成状态
            $("#txtEndTime").val(getNowFormatDate());
        }
        else {
            $("#txtEndTime").val("");
        }
    });

</script>
